Repository navigation
fix(codegen): escape reserved identifiers in generated namespaces - #11669
Open
AsadIqbal-Dev wants to merge 1 commit into
Open
AsadIqbal-Dev wants to merge 1 commit into
AsadIqbal-Dev wants to merge 1 commit into
Conversation
namespace @event generated OrleansCodeGen.event, which doesn't compile. Escape each segment in one place, and remove the escape again where metadata names are built, since those are matched against each other and passed to GetTypeByMetadataName.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11640
namespace @event;generatedOrleansCodeGen.event, which doesn't compile.GetNamespaceAndNestingreturns unescaped names, and four places built the generated namespace from it.GeneratedCodeUtilities.GetGeneratedNamespaceNamenow escapes each segment.SerializerGenerator,SerializableTypeDescriptionandProxyInterfaceDescriptioncall it instead of keeping their own copy. A keyword in an enclosing type's name goes through the same path.GetNamespaceAndNestingis unchanged, becauseTypeSymbolResolvercompares its raw output withmodel.Namespace.@, so a newGetMetadataNamespaceNameremoves it where they're built:GeneratedInvokableDescription,InvokableEmissionPlan,ProxyEmissionPlan,MetadataGeneratorandSerializerFactoryGenerator. These have to agree.MetadataGeneratormatches invokables against names from the proxy output, and a mismatch drops them from the manifest with no compile error. The new test checks for this, and I confirmed it fails when onlyMetadataGeneratoris left unchanged.EscapeIdentifieralso covers contextual keywords such asfromandget. A namespace with one of those as a segment already compiled, and now gets an@in the generated source and a different hint name hash. The generated types and their metadata names don't change.Tests in
ReservedIdentifierNamespaceTests:NamespaceWithReservedKeywordProducesValidGeneratedCode, for@eventandOuter.@class.Inner, with an enum, a class, a derived class, a generic class and a grain interface. It also looks up the generated types by metadata name.TypeNestedInReservedKeywordProducesValidGeneratedCode.The theory fails without the change with the errors from the issue.
Orleans.CodeGenerator.Testspasses on net10.0. I only ran that project.Microsoft Reviewers: Open in CodeFlow